
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Building LLVM With Autotools &mdash; LLVM 3.7 documentation</title>
    
    <link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '3.7',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="LLVM 3.7 documentation" href="index.html" />
    <link rel="next" title="Frequently Asked Questions (FAQ)" href="FAQ.html" />
    <link rel="prev" title="Getting Started with the LLVM System using Microsoft Visual Studio" href="GettingStartedVS.html" />
<style type="text/css">
  table.right { float: right; margin-left: 20px; }
  table.right td { border: 1px solid #ccc; }
</style>

  </head>
  <body role="document">
<div class="logo">
  <a href="index.html">
    <img src="_static/logo.png"
         alt="LLVM Logo" width="250" height="88"/></a>
</div>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="FAQ.html" title="Frequently Asked Questions (FAQ)"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="GettingStartedVS.html" title="Getting Started with the LLVM System using Microsoft Visual Studio"
             accesskey="P">previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>


    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <div class="section" id="building-llvm-with-autotools">
<h1>Building LLVM With Autotools<a class="headerlink" href="#building-llvm-with-autotools" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#overview" id="id2">Overview</a><ul>
<li><a class="reference internal" href="#a-quick-summary" id="id3">A Quick Summary</a></li>
<li><a class="reference internal" href="#local-llvm-configuration" id="id4">Local LLVM Configuration</a></li>
<li><a class="reference internal" href="#compiling-the-llvm-suite-source-code" id="id5">Compiling the LLVM Suite Source Code</a></li>
<li><a class="reference internal" href="#cross-compiling-llvm" id="id6">Cross-Compiling LLVM</a></li>
<li><a class="reference internal" href="#the-location-of-llvm-object-files" id="id7">The Location of LLVM Object Files</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id2">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>This document details how to use the LLVM autotools based build system to
configure and build LLVM from source. The normal developer process using CMake
is detailed <a class="reference external" href="GettingStarted.html#check-here">here</a>.</p>
<div class="section" id="a-quick-summary">
<h3><a class="toc-backref" href="#id3">A Quick Summary</a><a class="headerlink" href="#a-quick-summary" title="Permalink to this headline">¶</a></h3>
<ol class="arabic simple">
<li>Configure and build LLVM and Clang:<ul>
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">where-you-want-to-build-llvm</span></code></li>
<li><code class="docutils literal"><span class="pre">mkdir</span> <span class="pre">build</span></code> (for building without polluting the source dir)</li>
<li><code class="docutils literal"><span class="pre">cd</span> <span class="pre">build</span></code></li>
<li><code class="docutils literal"><span class="pre">../llvm/configure</span> <span class="pre">[options]</span></code>
Some common options:<ul>
<li><code class="docutils literal"><span class="pre">--prefix=directory</span></code> &#8212; Specify for <em>directory</em> the full pathname of
where you want the LLVM tools and libraries to be installed (default
<code class="docutils literal"><span class="pre">/usr/local</span></code>).</li>
<li><code class="docutils literal"><span class="pre">--enable-optimized</span></code> &#8212; Compile with optimizations enabled (default
is NO).</li>
<li><code class="docutils literal"><span class="pre">--enable-assertions</span></code> &#8212; Compile with assertion checks enabled
(default is YES).</li>
</ul>
</li>
<li><code class="docutils literal"><span class="pre">make</span> <span class="pre">[-j]</span></code> &#8212; The <code class="docutils literal"><span class="pre">-j</span></code> specifies the number of jobs (commands) to run
simultaneously.  This builds both LLVM and Clang for Debug+Asserts mode.
The <code class="docutils literal"><span class="pre">--enable-optimized</span></code> configure option is used to specify a Release
build.</li>
<li><code class="docutils literal"><span class="pre">make</span> <span class="pre">check-all</span></code> &#8212; This run the regression tests to ensure everything
is in working order.</li>
<li>If you get an &#8220;internal compiler error (ICE)&#8221; or test failures, see
<a class="reference external" href="GettingStarted.html#check-here">here</a>.</li>
</ul>
</li>
</ol>
</div>
<div class="section" id="local-llvm-configuration">
<h3><a class="toc-backref" href="#id4">Local LLVM Configuration</a><a class="headerlink" href="#local-llvm-configuration" title="Permalink to this headline">¶</a></h3>
<p>Once checked out from the Subversion repository, the LLVM suite source code must
be configured via the <code class="docutils literal"><span class="pre">configure</span></code> script.  This script sets variables in the
various <code class="docutils literal"><span class="pre">*.in</span></code> files, most notably <code class="docutils literal"><span class="pre">llvm/Makefile.config</span></code> and
<code class="docutils literal"><span class="pre">llvm/include/Config/config.h</span></code>.  It also populates <em>OBJ_ROOT</em> with the
Makefiles needed to begin building LLVM.</p>
<p>The following environment variables are used by the <code class="docutils literal"><span class="pre">configure</span></code> script to
configure the build system:</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="83%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Variable</th>
<th class="head">Purpose</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>CC</td>
<td>Tells <code class="docutils literal"><span class="pre">configure</span></code> which C compiler to use.  By default,
<code class="docutils literal"><span class="pre">configure</span></code> will check <code class="docutils literal"><span class="pre">PATH</span></code> for <code class="docutils literal"><span class="pre">clang</span></code> and GCC C
compilers (in this order).  Use this variable to override
<code class="docutils literal"><span class="pre">configure</span></code>&#8216;s  default behavior.</td>
</tr>
<tr class="row-odd"><td>CXX</td>
<td>Tells <code class="docutils literal"><span class="pre">configure</span></code> which C++ compiler to use.  By
default, <code class="docutils literal"><span class="pre">configure</span></code> will check <code class="docutils literal"><span class="pre">PATH</span></code> for
<code class="docutils literal"><span class="pre">clang++</span></code> and GCC C++ compilers (in this order).  Use
this variable to override  <code class="docutils literal"><span class="pre">configure</span></code>&#8216;s default
behavior.</td>
</tr>
</tbody>
</table>
<p>The following options can be used to set or enable LLVM specific options:</p>
<p><code class="docutils literal"><span class="pre">--enable-optimized</span></code></p>
<blockquote>
<div>Enables optimized compilation (debugging symbols are removed and GCC
optimization flags are enabled). Note that this is the default setting if you
are using the LLVM distribution. The default behavior of a Subversion
checkout is to use an unoptimized build (also known as a debug build).</div></blockquote>
<p><code class="docutils literal"><span class="pre">--enable-debug-runtime</span></code></p>
<blockquote>
<div>Enables debug symbols in the runtime libraries. The default is to strip debug
symbols from the runtime libraries.</div></blockquote>
<p><code class="docutils literal"><span class="pre">--enable-jit</span></code></p>
<blockquote>
<div>Compile the Just In Time (JIT) compiler functionality.  This is not available
on all platforms.  The default is dependent on platform, so it is best to
explicitly enable it if you want it.</div></blockquote>
<p><code class="docutils literal"><span class="pre">--enable-targets=target-option</span></code></p>
<blockquote>
<div><p>Controls which targets will be built and linked into llc. The default value
for <code class="docutils literal"><span class="pre">target_options</span></code> is &#8220;all&#8221; which builds and links all available targets.
The &#8220;host&#8221; target is selected as the target of the build host. You can also
specify a comma separated list of target names that you want available in llc.
The target names use all lower case. The current set of targets is:</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">aarch64,</span> <span class="pre">arm,</span> <span class="pre">arm64,</span> <span class="pre">cpp,</span> <span class="pre">hexagon,</span> <span class="pre">mips,</span> <span class="pre">mipsel,</span> <span class="pre">mips64,</span> <span class="pre">mips64el,</span> <span class="pre">msp430,</span>
<span class="pre">powerpc,</span> <span class="pre">nvptx,</span> <span class="pre">r600,</span> <span class="pre">sparc,</span> <span class="pre">systemz,</span> <span class="pre">x86,</span> <span class="pre">x86_64,</span> <span class="pre">xcore</span></code>.</div></blockquote>
</div></blockquote>
<p><code class="docutils literal"><span class="pre">--enable-doxygen</span></code></p>
<blockquote>
<div>Look for the doxygen program and enable construction of doxygen based
documentation from the source code. This is disabled by default because
generating the documentation can take a long time and producess 100s of
megabytes of output.</div></blockquote>
<p>To configure LLVM, follow these steps:</p>
<ol class="arabic">
<li><p class="first">Change directory into the object root directory:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>OBJ_ROOT
</pre></div>
</div>
</li>
<li><p class="first">Run the <code class="docutils literal"><span class="pre">configure</span></code> script located in the LLVM source tree:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nv">$LLVM_SRC_DIR</span>/configure --prefix<span class="o">=</span>/install/path <span class="o">[</span>other options<span class="o">]</span>
</pre></div>
</div>
</li>
</ol>
</div>
<div class="section" id="compiling-the-llvm-suite-source-code">
<h3><a class="toc-backref" href="#id5">Compiling the LLVM Suite Source Code</a><a class="headerlink" href="#compiling-the-llvm-suite-source-code" title="Permalink to this headline">¶</a></h3>
<p>Once you have configured LLVM, you can build it.  There are three types of
builds:</p>
<p>Debug Builds</p>
<blockquote>
<div>These builds are the default when one is using a Subversion checkout and
types <code class="docutils literal"><span class="pre">gmake</span></code> (unless the <code class="docutils literal"><span class="pre">--enable-optimized</span></code> option was used during
configuration).  The build system will compile the tools and libraries with
debugging information.  To get a Debug Build using the LLVM distribution the
<code class="docutils literal"><span class="pre">--disable-optimized</span></code> option must be passed to <code class="docutils literal"><span class="pre">configure</span></code>.</div></blockquote>
<p>Release (Optimized) Builds</p>
<blockquote>
<div>These builds are enabled with the <code class="docutils literal"><span class="pre">--enable-optimized</span></code> option to
<code class="docutils literal"><span class="pre">configure</span></code> or by specifying <code class="docutils literal"><span class="pre">ENABLE_OPTIMIZED=1</span></code> on the <code class="docutils literal"><span class="pre">gmake</span></code> command
line.  For these builds, the build system will compile the tools and libraries
with GCC optimizations enabled and strip debugging information from the
libraries and executables it generates.  Note that Release Builds are default
when using an LLVM distribution.</div></blockquote>
<p>Profile Builds</p>
<blockquote>
<div>These builds are for use with profiling.  They compile profiling information
into the code for use with programs like <code class="docutils literal"><span class="pre">gprof</span></code>.  Profile builds must be
started by specifying <code class="docutils literal"><span class="pre">ENABLE_PROFILING=1</span></code> on the <code class="docutils literal"><span class="pre">gmake</span></code> command line.</div></blockquote>
<p>Once you have LLVM configured, you can build it by entering the <em>OBJ_ROOT</em>
directory and issuing the following command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> gmake
</pre></div>
</div>
<p>If the build fails, please <a class="reference external" href="GettingStarted.html#check-here">check here</a>
to see if you are using a version of GCC that is known not to compile LLVM.</p>
<p>If you have multiple processors in your machine, you may wish to use some of the
parallel build options provided by GNU Make.  For example, you could use the
command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> gmake -j2
</pre></div>
</div>
<p>There are several special targets which are useful when working with the LLVM
source code:</p>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">clean</span></code></p>
<blockquote>
<div>Removes all files generated by the build.  This includes object files,
generated C/C++ files, libraries, and executables.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">dist-clean</span></code></p>
<blockquote>
<div>Removes everything that <code class="docutils literal"><span class="pre">gmake</span> <span class="pre">clean</span></code> does, but also removes files generated
by <code class="docutils literal"><span class="pre">configure</span></code>.  It attempts to return the source tree to the original state
in which it was shipped.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">install</span></code></p>
<blockquote>
<div>Installs LLVM header files, libraries, tools, and documentation in a hierarchy
under <code class="docutils literal"><span class="pre">$PREFIX</span></code>, specified with <code class="docutils literal"><span class="pre">$LLVM_SRC_DIR/configure</span> <span class="pre">--prefix=[dir]</span></code>, which
defaults to <code class="docutils literal"><span class="pre">/usr/local</span></code>.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">-C</span> <span class="pre">runtime</span> <span class="pre">install-bytecode</span></code></p>
<blockquote>
<div>Assuming you built LLVM into $OBJDIR, when this command is run, it will
install bitcode libraries into the GCC front end&#8217;s bitcode library directory.
If you need to update your bitcode libraries, this is the target to use once
you&#8217;ve built them.</div></blockquote>
<p>Please see the <a class="reference external" href="MakefileGuide.html">Makefile Guide</a> for further details on
these <code class="docutils literal"><span class="pre">make</span></code> targets and descriptions of other targets available.</p>
<p>It is also possible to override default values from <code class="docutils literal"><span class="pre">configure</span></code> by declaring
variables on the command line.  The following are some examples:</p>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">ENABLE_OPTIMIZED=1</span></code></p>
<blockquote>
<div>Perform a Release (Optimized) build.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">ENABLE_OPTIMIZED=1</span> <span class="pre">DISABLE_ASSERTIONS=1</span></code></p>
<blockquote>
<div>Perform a Release (Optimized) build without assertions enabled.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">ENABLE_OPTIMIZED=0</span></code></p>
<blockquote>
<div>Perform a Debug build.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">ENABLE_PROFILING=1</span></code></p>
<blockquote>
<div>Perform a Profiling build.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">VERBOSE=1</span></code></p>
<blockquote>
<div>Print what <code class="docutils literal"><span class="pre">gmake</span></code> is doing on standard output.</div></blockquote>
<p><code class="docutils literal"><span class="pre">gmake</span> <span class="pre">TOOL_VERBOSE=1</span></code></p>
<blockquote>
<div>Ask each tool invoked by the makefiles to print out what it is doing on
the standard output. This also implies <code class="docutils literal"><span class="pre">VERBOSE=1</span></code>.</div></blockquote>
<p>Every directory in the LLVM object tree includes a <code class="docutils literal"><span class="pre">Makefile</span></code> to build it and
any subdirectories that it contains.  Entering any directory inside the LLVM
object tree and typing <code class="docutils literal"><span class="pre">gmake</span></code> should rebuild anything in or below that
directory that is out of date.</p>
<p>This does not apply to building the documentation.
LLVM&#8217;s (non-Doxygen) documentation is produced with the
<a class="reference external" href="http://sphinx-doc.org/">Sphinx</a> documentation generation system.
There are some HTML documents that have not yet been converted to the new
system (which uses the easy-to-read and easy-to-write
<a class="reference external" href="http://sphinx-doc.org/rest.html">reStructuredText</a> plaintext markup
language).
The generated documentation is built in the <code class="docutils literal"><span class="pre">$LLVM_SRC_DIR/docs</span></code> directory using
a special makefile.
For instructions on how to install Sphinx, see
<a class="reference external" href="http://lld.llvm.org/sphinx_intro.html">Sphinx Introduction for LLVM Developers</a>.
After following the instructions there for installing Sphinx, build the LLVM
HTML documentation by doing the following:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> <span class="nb">cd</span> <span class="nv">$LLVM_SRC_DIR</span>/docs
<span class="gp">$</span> make -f Makefile.sphinx
</pre></div>
</div>
<p>This creates a <code class="docutils literal"><span class="pre">_build/html</span></code> sub-directory with all of the HTML files, not
just the generated ones.
This directory corresponds to <code class="docutils literal"><span class="pre">llvm.org/docs</span></code>.
For example, <code class="docutils literal"><span class="pre">_build/html/SphinxQuickstartTemplate.html</span></code> corresponds to
<code class="docutils literal"><span class="pre">llvm.org/docs/SphinxQuickstartTemplate.html</span></code>.
The <a class="reference internal" href="SphinxQuickstartTemplate.html"><em>Sphinx Quickstart Template</em></a> is useful when creating a new document.</p>
</div>
<div class="section" id="cross-compiling-llvm">
<h3><a class="toc-backref" href="#id6">Cross-Compiling LLVM</a><a class="headerlink" href="#cross-compiling-llvm" title="Permalink to this headline">¶</a></h3>
<p>It is possible to cross-compile LLVM itself. That is, you can create LLVM
executables and libraries to be hosted on a platform different from the platform
where they are built (a Canadian Cross build). To configure a cross-compile,
supply the configure script with <code class="docutils literal"><span class="pre">--build</span></code> and <code class="docutils literal"><span class="pre">--host</span></code> options that are
different. The values of these options must be legal target triples that your
GCC compiler supports.</p>
<p>The result of such a build is executables that are not runnable on on the build
host (&#8211;build option) but can be executed on the compile host (&#8211;host option).</p>
<p>Check <a class="reference internal" href="HowToCrossCompileLLVM.html"><em>How To Cross-Compile Clang/LLVM using Clang/LLVM</em></a> and <a class="reference external" href="http://clang.llvm.org/docs/CrossCompilation.html">Clang docs on how to cross-compile in general</a> for more information
about cross-compiling.</p>
</div>
<div class="section" id="the-location-of-llvm-object-files">
<h3><a class="toc-backref" href="#id7">The Location of LLVM Object Files</a><a class="headerlink" href="#the-location-of-llvm-object-files" title="Permalink to this headline">¶</a></h3>
<p>The LLVM build system is capable of sharing a single LLVM source tree among
several LLVM builds.  Hence, it is possible to build LLVM for several different
platforms or configurations using the same source tree.</p>
<p>This is accomplished in the typical autoconf manner:</p>
<ul>
<li><p class="first">Change directory to where the LLVM object files should live:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nb">cd </span>OBJ_ROOT
</pre></div>
</div>
</li>
<li><p class="first">Run the <code class="docutils literal"><span class="pre">configure</span></code> script found in the LLVM source directory:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">%</span> <span class="nv">$LLVM_SRC_DIR</span>/configure
</pre></div>
</div>
</li>
</ul>
<p>The LLVM build will place files underneath <em>OBJ_ROOT</em> in directories named after
the build type:</p>
<p>Debug Builds with assertions enabled (the default)</p>
<blockquote>
<div><p>Tools</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Debug+Asserts/bin</span></code></div></blockquote>
<p>Libraries</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Debug+Asserts/lib</span></code></div></blockquote>
</div></blockquote>
<p>Release Builds</p>
<blockquote>
<div><p>Tools</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Release/bin</span></code></div></blockquote>
<p>Libraries</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Release/lib</span></code></div></blockquote>
</div></blockquote>
<p>Profile Builds</p>
<blockquote>
<div><p>Tools</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Profile/bin</span></code></div></blockquote>
<p>Libraries</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">OBJ_ROOT/Profile/lib</span></code></div></blockquote>
</div></blockquote>
</div>
</div>
</div>


          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="FAQ.html" title="Frequently Asked Questions (FAQ)"
             >next</a> |</li>
        <li class="right" >
          <a href="GettingStartedVS.html" title="Getting Started with the LLVM System using Microsoft Visual Studio"
             >previous</a> |</li>
  <li><a href="http://llvm.org/">LLVM Home</a>&nbsp;|&nbsp;</li>
  <li><a href="index.html">Documentation</a>&raquo;</li>
 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2003-2015, LLVM Project.
      Last updated on 2015-09-08.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
    </div>
  </body>
</html>